package servlet;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class httpServlet2 extends HttpServlet {
    @Override
    public void init() throws ServletException {
//        super.init(conf);
        System.out.println("重写init方法");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取配置对象
        ServletConfig conf =getServletConfig();
        //获取配置参数
        String name =conf.getInitParameter("name");
        String url = conf.getInitParameter("url");
        System.out.println(conf);
        System.out.println("config     name="+name+"     url="+url);
        //获取上下文对象
        ServletContext context = getServletContext();
        //获取初始化上下文参数
        String s1 =context.getInitParameter("user");
        String s2 = context.getInitParameter("user1");
        System.out.println(s1+"           "+s2);
        String path = context.getContextPath();
        System.out.println("当前工程路径="+path);
        String path12 = context.getRealPath("/");
        System.out.println("绝对工程路径="+path12);
        String path1 = context.getRealPath("/libs");
        System.out.println("libs绝对工程路径="+path1);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
